package com.thunder.soft.ui.activity;

import android.widget.ImageView;
import android.widget.Toast;

import androidx.lifecycle.Observer;

import com.thunder.soft.R;
import com.thunder.soft.common.base.BaseActivity;
import com.thunder.soft.common.util.FileUtils;
import com.thunder.soft.common.util.ViewModelProviderHelper;
import com.thunder.soft.databinding.ActivityAboutAutherBinding;
import com.thunder.soft.vm.AboutAutherViewModel;

import java.util.Map;

public class AboutAutherActivity extends BaseActivity<ActivityAboutAutherBinding> {

    private AboutAutherViewModel aboutAutherViewModel;

    @Override
    protected void initData() {

        aboutAutherViewModel = ViewModelProviderHelper.buildViewModel(this, AboutAutherViewModel.class);
        getLifecycle().addObserver(aboutAutherViewModel);
        binding.setAboutAutherViewModel(aboutAutherViewModel);

        aboutAutherViewModel.getErrorMsg().observe(this, new Observer<String>() {
            @Override
            public void onChanged(String s) {
                Toast.makeText(AboutAutherActivity.this, s, Toast.LENGTH_SHORT).show();
            }
        });

        // 关闭页面
        aboutAutherViewModel.getFinishActivity().observe(this, new Observer<Integer>() {
            @Override
            public void onChanged(Integer integer) {
                finish();
            }
        });

        aboutAutherViewModel.getActivityLiveData().observe(this, new Observer<Map<String, Object>>() {
            @Override
            public void onChanged(Map<String, Object> value) {
                ImageView imageview = (ImageView) value.get("imageview");
                FileUtils.saveImage(AboutAutherActivity.this, imageview);
                Toast.makeText(AboutAutherActivity.this,"保存成功",Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    protected int layoutId() {
        return R.layout.activity_about_auther;
    }
}